<?php
namespace app\api\logic;
use function AlibabaCloud\Client\value;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use app\common\model\UserLevelPay;
use think\Db;

class UserLevelLogic{
    /**
     * note 会员等级
     */
    public static function lists(){

        $user_level_list = Db::name('user_level')
                    ->where(['delete_time '=>0])
                    ->order('discount DESC')
                    ->field('id,name,discount,image,background_image,money,num,type')
                    ->select();
        foreach ($user_level_list as &$level){
            $level['image'] = UrlServer::getFileUrl($level['image']);
            $level['background_image'] = UrlServer::getFileUrl($level['background_image']);
        }
        return $user_level_list;
    }

    //缴费记录
    public static function UserVipLogList($user_id,$get,$page,$size){
        $where = [];
        $order = [];
        $where[] = ['uvp.order_status','=',20];
        $where[] = ['uvp.delete_time','=',0];
        $count = UserLevelPay::alias('uvp')
                    ->join('user_level uv','uv.id=uvp.user_vip_id')
                    ->where($where)->count();

        $list = UserLevelPay::alias('uvp')
                        ->join('user_level uv','uv.id=uvp.user_vip_id')
                        ->where($where)
                        ->page($page,$size)
                        ->order('uvp.id desc')
                        ->field('uv.name,uvp.type,uvp.money,uvp.pay_time')
                        ->select();
        $more = is_more($count,$page,$size);  //是否有下一页
        $data = [
            'list'          => $list,
            'page_no'       => $page,
            'page_size'     => $size,
            'count'         => $count,
            'more'          => $more
        ];
        return $data;
    }
}